package com.bocai.grainshop.sreach.controller;

import com.bocai.grainshop.sreach.service.SearchServiceByParam;
import com.bocai.grainshop.sreach.vo.SearchParam;
import com.bocai.grainshop.sreach.vo.SearchResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import javax.servlet.http.HttpServletRequest;

@Controller
@Slf4j
public class SearchController {

    @Autowired
    private SearchServiceByParam serviceByParam;

    @GetMapping("/list.html")
    public Object getSearch(SearchParam searchParam, Model model, HttpServletRequest request){
        String queryString = request.getQueryString();
        searchParam.set_queryString(queryString);
        SearchResult search = serviceByParam.search(searchParam);
        model.addAttribute("result",search);
        return "list";
    }
}
